package com.itestor.iptv.global.actions;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * 抽象的Ajax数据响应Action.
 */
public abstract class AbstractAjaxResponseAction extends Action {

	/**
	 * Logger for this class.
	 */
	private static final Logger logger = Logger.getLogger(AbstractAjaxResponseAction.class);

	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setContentType("text/xml");
		response.setHeader("Cache-Control", "no-cache");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		String s = buildData(form, request);
		logger.info("Ajax Data - " + s);
		out.write(s);
		out.close();
		return null;
	}

	public abstract String buildData(ActionForm form, HttpServletRequest request);
}